/*
 * 文件名： Main.java
 *
 * 创建日期： 2016年12月6日
 *
 * Copyright(C) 2016, by <a href="mailto:liws@xingyuanauto.com">liws</a>.
 *
 * 原始作者: liws
 *
 */
package com.moli.iov.gateway;

import com.moli.iov.gateway.server.NettyChannelManager;
import com.moli.iov.gateway.server.NettyServer;
import com.moli.iov.gateway.util.MBeanUtils;
import com.moli.iov.util.PropertiesUtils;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.management.ObjectName;

/**
 * 启动数据上报客户端
 *
 * @author <a href="mailto:liws@xingyuanauto.com">liws</a>
 * @version $Revision$
 * @since 2016年12月6日
 */
public class StartGateway {

    private static final Logger logger = LoggerFactory.getLogger(StartGateway.class);

    public static void main(String[] args) {
        init();
    }

    private static void init() {
        try {
            //加载spring配置文件
            ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("spring/spring-base.xml");
            ctx.start();
            //注册MBean NettyChannelManager
            ObjectName objName = new ObjectName("com.moli.iov.gateway.server:name=NettyChannelManager");
            final NettyChannelManager ncManager = NettyChannelManager.getInstance();
            MBeanUtils.registerMBean(ncManager, objName);
            //获取端口号,启动Server
            int serverPort = Integer.parseInt(PropertiesUtils.getProperty("netty.server.port"));
            new NettyServer(serverPort);


        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            System.out.println(e.getMessage());
        }
    }

}
